package com.stary.code.util;

import java.sql.Connection;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;

/**
 * 
 * <p>mybaits 读取并执行sql</p>
 * @author stary
 * @since 2018年10月24日
 */
public class SqlFileExecutor {


	/**
	 * 执行sql脚本
	 * @param conn 连接
	 * @param sqlFile sql脚本文件
	 * @throws Exception
	 */
	public static void execute(Connection conn, String sqlFile) throws Exception {
		ScriptRunner runner = new ScriptRunner(conn);
		runner.setLogWriter(null);
		runner.runScript(Resources.getResourceAsReader(sqlFile));	
	}
}